<?php

/**
 * @author Leon Kim
 * @copyright 2008
 */

class Date {

  /**
   * Date::dateUsToFr()
   * Modification du format de la date : m/d/Y --> d/m/Y
   * en parametre il faut pr�cis� le caractere de s�paration en entr�e et en sortie.
   * (v�rification de la date pass� en parametre si valide ou non)
   *
   * @param mixed $dateUs
   * @param mixed $sepIn
   * @param mixed $sepOut
   * @return
   */
  public static function dateUsToFr($dateUs,$sepIn,$sepOut) {
    if(intval(str_replace($sepIn,"",$dateUs)) > 0) {
      if(Verif::checkDateUs($dateUs,$sepIn)) {
        $d1 = explode($sepIn, $dateUs);
        $dateFr = date("d".$sepOut."m".$sepOut."Y",mktime(0,0,0, $d1[1], $d1[2], $d1[0]));
        return $dateFr;
      }
      else {
        throw new Exception ("Date invalide");
      }
    }

    return "";
  }


  /**
   * Date::dateFrToUs()
   * Modification du format de la date : d/m/Y --> Y/m/d
   * en parametre il faut pr�cis� le caractere de s�paration en entr�e et en sortie.
   * (v�rification de la date pass� en parametre si valide ou non)
   *
   * @param mixed $dateFr
   * @param mixed $sepIn
   * @param mixed $sepOut
   * @return
   */
  public static function dateFrToUs($dateFr,$sepIn,$sepOut) {
    if(Verif::checkDateFr($dateFr,$sepIn)) {
      $d1 = explode($sepIn, $dateFr);
      $dateUs = date("Y".$sepOut."m".$sepOut."d",mktime(0,0,0, $d1[1], $d1[0], $d1[2]));
      return $dateUs;
    }
  }




  /**
   *	Date::getDate()
   * 	Fonction permettant de r�cup�rer la date d'un datetime sous la forme d/m/Y
   * 	@param mixed datetime
   *
   */
  public static function getDate($dateTime) {
    list($date, $time) = explode(' ', $dateTime);
    $date = Date::dateUsToFr($date, '-', '/');
    return $date;
  }

  /**
   *	Date::getHeure()
   * 	Fonction permettant de r�cup�rer l'heure d'un datetime
   * 	@param mixed datetime
   *
   */
  public static function getHeure($dateTime) {
    list($date, $time) = explode(' ', $dateTime);
    list($heure, $minutes, $secondes) = explode(':', $time);
    return $heure;
  }

  /**
   *	Date::getMinutes()
   * 	Fonction permettant de r�cup�rer les minutes d'un datetime
   * 	@param mixed datetime
   *
   */
  public static function getMinutes($dateTime) {
    list($date, $time) = explode(' ', $dateTime);
    list($heure, $minutes, $secondes) = explode(':', $time);
    return $minutes;
  }

  /**
   *	Date::getSecondes()
   * 	Fonction permettant de r�cup�rer les secondes d'un datetime
   * 	@param mixed datetime
   *
   */
  public static function getSecondes($dateTime) {
    list($date, $time) = explode(' ', $dateTime);
    list($heure, $minutes, $secondes) = explode(':', $time);
    return $secondes;
  }

  public static function getHeureComplete($dateTime) {
    return Date::getHeure($dateTime).":".Date::getMinutes($dateTime).":".Date::getSecondes($dateTime);
  }

  public static function dateFrToMysqlDatetime($dateFr) {
    return Date::dateFrToUs($dateFr,"/","-");
  }
}


?>